home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / atari / c / zilog / zilog_it.c < prev    next >
C/C++ Source or Header  |  1996-04-07  |  6KB  |  245 lines

  1. /*
  2.  *
  3.  *
  4.  *        Programme d‚monstration IT- Terminal entre deux machines
  5.  *
  6.  *        Ce programme transfŠre … 19200 Bits/Sec. en 8 Bits Parit‚ Paire
  7.  *        1 bit de Stop.
  8.  *        Il opŠre en mode simple pour l'‚mission d'un caratŠre
  9.  *        mais re‡oit sous interruption.
  10.  *
  11.  *
  12.  *        FunShip (c) 28 Avril 1995 - ATARI Falcon030
  13.  *
  14.  */
  15.  
  16.  
  17. #include <stdio.h>
  18. #include <tos.h>
  19.  
  20. /*
  21.  *    Proc‚dure d'interruption
  22.  */
  23.  
  24. extern    void ItSubRoutine(void);
  25.  
  26. #define    TRUE        1
  27. #define    FALSE        0
  28.  
  29. #define    SCC_CONTROLA    0xFFFF8C81L        /* Registers Z85C30's addresses*/
  30. #define    SCC_DATAA    0xFFFF8C83L
  31. #define    SCC_CONTROLB    0xFFFF8C85L
  32. #define    SCC_DATAB    0xFFFF8C87L
  33.  
  34. #define    IT_VECTOR    0x82            /* A free interrupt vector user */
  35.  
  36. #define    WR1        1
  37. #define    WR2        2
  38. #define    WR3        3
  39. #define    WR4        4
  40. #define    WR5        5
  41. #define    WR6        6
  42. #define    WR7        7
  43. #define    WR8        8
  44. #define    WR9        9
  45. #define    WR10        10
  46. #define    WR11        11
  47. #define    WR12        12
  48. #define    WR13        13
  49. #define    WR14        14
  50. #define    WR15        15
  51.  
  52. #define    RR1        1
  53. #define    RR2        2
  54. #define    RR3        3
  55. #define    RR10        10
  56. #define    RR12        12
  57. #define    RR13        13
  58. #define    RR15        15
  59.  
  60. void     (*OldVector)();                /* Old It vector */
  61. int    Echange;                /* to exchange datas with IT prg */
  62.  
  63. /*
  64.  *        Primitives d'accŠs aux registres du ZILOG
  65.  */
  66.  
  67. void SCCPut(int Canal,int Value,int Register)
  68. /*
  69.     This procedure put a value in any register of Z85C30
  70.     
  71.     Inputs:    Value is the byte value to store
  72.         Register is the number of target register
  73.     Outputs:None
  74. */
  75. {
  76.   if(Canal == 'B')
  77.   {
  78.     *(char *)SCC_CONTROLB    = Register;
  79.     *(char *)SCC_CONTROLB    = Value;
  80.   }
  81.   else
  82.   {
  83.     *(char *)SCC_CONTROLA    = Register;
  84.     *(char *)SCC_CONTROLA    = Value;
  85.   }
  86. }
  87.  
  88. int SCCGet(int Channel, int Register)
  89. /*
  90.     This function read a value from any register of Z85C30
  91.     
  92.     Inputs:    Register is the number of source register
  93.     Outputs:Return the register's value
  94. */
  95. {
  96.   int    Value;
  97.   
  98.   if(Channel == 'B')
  99.   {
  100.     *(char *)SCC_CONTROLB    = Register;
  101.     Value            = *(char *)SCC_CONTROLB;
  102.   }
  103.   else
  104.   {
  105.     *(char *)SCC_CONTROLA    = Register;
  106.     Value            = *(char *)SCC_CONTROLA;
  107.   }
  108.   return(Value);
  109. }
  110.  
  111. /*
  112.  *    Primitives plus haut niveaux: Initialisation, Emission, Test et R‚ception
  113.  */
  114.  
  115. void SCCInit(int Channel)
  116. /*
  117.     Initialize the chip in 19200 Bits/Sec, Parity Even, 1 Stop bit and 8 Bits Data
  118.     No interrupts required.
  119. */
  120. {
  121.   SCCPut(Channel,0x00,WR3);            /* Receiver Off */
  122.   SCCPut(Channel,0x00,WR5);            /* Transceiver Off */
  123.   SCCPut(Channel,0x14,WR1);            /* ITs for every bytes and parity error */
  124.   SCCPut(Channel,IT_VECTOR,WR2);        /* Interrupt Vector */
  125.   SCCPut(Channel,0x47,WR4);            /* Async. 1 Stop parity Even and Clk/16 */
  126.   SCCPut(Channel,0x08,WR9);            /* Enable interrupts */
  127.   SCCPut(Channel,0x00,WR10);            /* NRZ Code mode -> RS232C */
  128.   SCCPut(Channel,0x50,WR11);            /* RxClk = TxClk = BR */
  129.   SCCPut(Channel,0x00,WR15);            /* No special interrupts */
  130.   SCCPut(Channel,0xA3,WR14);            /* BR -> PCLK */
  131.   SCCPut(Channel,0x0B,WR12);            /* Divide value LSB */
  132.   SCCPut(Channel,0x00,WR13);            /* Divide value MSB => 19200 Bauds */
  133.  
  134.   OldVector = Setexc(IT_VECTOR,ItSubRoutine);      /* Install new interrupt handler*/
  135.   
  136.   SCCPut(Channel,0xC1,WR3);            /* 8 Bits and enable receiver */
  137.   SCCPut(Channel,0xE8,WR5);            /* 8 Bits and ebale transceiver */
  138. }
  139.  
  140. void SCCStop(int Channel)
  141. /*
  142.     Disable the Zilog in receive and transmit mode. Delete our own It also.
  143. */
  144. {
  145.   SCCPut(Channel,0x00,WR3);            /* Receiver Off */
  146.   SCCPut(Channel,0x00,WR5);            /* Transceiver Off */
  147.   SCCPut(Channel,0x00,WR9);            /* no more ITs */  
  148. }
  149.  
  150. void SCCOut(int Channel, int Byte)
  151. /*
  152.     Send a character trough the output data register.
  153. */
  154. {
  155.   if(Channel == 'B')
  156.     *(char *)SCC_DATAB = Byte;
  157.   else
  158.     *(char *)SCC_DATAA = Byte;
  159. }
  160.  
  161. int SCCReceived(int Channel)
  162. /*
  163.     Return True if a character is received else false. A character is arrived if
  164.     the bit 0 of RR0 is set.
  165. */
  166. {
  167.   int    Etat;
  168.   
  169.   if(Channel == 'B')
  170.     Etat = *(char *)SCC_CONTROLB & 0x01;
  171.   else
  172.     Etat = *(char *)SCC_CONTROLA & 0x01; 
  173.   return(Etat); 
  174. }
  175.  
  176. int SCCIn(int Channel)
  177. /*
  178.     Get a character from the input data register.
  179. */
  180. {
  181.   if(Channel == 'B')
  182.     return(*(char *)SCC_DATAB);
  183.   else
  184.     return(*(char *)SCC_DATAA);
  185. }
  186.  
  187. /*
  188.  *    Programme principal de test
  189.  */
  190.  
  191. int main(void)
  192. {
  193.   unsigned int    Character;
  194.   int        *OldPile;
  195.   int        Colonne;
  196.   
  197.   printf("\033E");
  198.   printf("\t\tZILOG Z85C30: Reception by Interrupt program\n");
  199.   printf("\t\tPress ESC to exit\n");
  200.   printf("\t\t============================================\n\n");
  201.  
  202.   printf("Z85C30 programmed at 19200 bits/s, Parity even, 1 Stop bit and 8 bits data\n");
  203.   printf("On its B Channel\n\n");
  204.   
  205.   OldPile    = (int *)Super(0L);        /* Go to supervisor mode */
  206.   
  207.   SCCInit('B');                    /* Initialize the Zilog */
  208.   Colonne = 1;
  209.   Echange = 0;
  210.   Character = (unsigned char)Crawio(0xFF);    /* Reading a character */
  211.   while(Character != 27)
  212.   {
  213.     if(Character != 0)                /* a key is pressed */
  214.     {
  215.       if(Colonne < 80)
  216.         Colonne++;
  217.       else                    /* Go back top line */
  218.       {
  219.         Colonne = 1;
  220.         printf("\n");
  221.       }
  222.       printf("%c",Character);
  223.       SCCOut('B',Character);            /* Sending its ASCII code */
  224.     }
  225.     if(Echange != 0)                /* If a character is arrived */
  226.     {
  227.       if(Colonne < 80)
  228.         Colonne++;
  229.       else                    /* Go back top line */
  230.       {
  231.         Colonne = 1;
  232.         printf("\n");
  233.       }
  234.       printf("%c",Echange);            /* Display it */
  235.       Echange = 0;
  236.     }
  237.     Character = (unsigned char)Crawio(0xFF);    /* Test another key */
  238.   }
  239.   SCCStop('B');                    /* Stop channel B */
  240.   Setexc(IT_VECTOR,OldVector);            /* Restore old IT Vector */
  241.   Super(OldPile);                /* Go back user mode */
  242.   return(0);                    /* Return code for the Shell */
  243. }
  244.  
  245.